package authoritah.ui.eventtype;

import java.awt.BorderLayout;

import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;

import authoritah.db.EventType;


public class EventTypeView extends JPanel {
	private EventTypeModel model;
	
	private JTable eventTypeList;
	private JScrollPane eventTypeListScroll;

	private JToolBar toolBar;
	
	private JButton addEvent;
	private JButton removeEvent;
	private JButton editEvent;
	
	public EventTypeView(EventTypeModel model) {
		super();
		this.model = model;
		
		initComponents();
		layoutComponents();
	}
	
	private void initComponents() {
		eventTypeList = new JTable(model);
		eventTypeListScroll = new JScrollPane(eventTypeList);
		
		toolBar = new JToolBar();
		
		addEvent = new JButton();		
		removeEvent = new JButton();
		editEvent = new JButton();
	}
	
	private void layoutComponents() {		
		toolBar.add(addEvent);
		toolBar.add(editEvent);
		toolBar.add(removeEvent);
		toolBar.setOrientation(JToolBar.VERTICAL);
		
		this.setLayout(new BorderLayout());
		this.add(toolBar, BorderLayout.WEST);
		this.add(eventTypeListScroll, BorderLayout.CENTER);
	}
	
	public void setIcons() {
		addEvent.setIcon(new ImageIcon("res/book_add.png"));
		removeEvent.setIcon(new ImageIcon("res/book_delete.png"));
		editEvent.setIcon(new ImageIcon("res/book_edit.png"));
	}
	
	public void setAddAction(Action action){
		addEvent.setAction(action);
	}
	
	public void setRemoveAction(Action action){
		removeEvent.setAction(action);
	}
	
	public void setEditAction(Action action){
		editEvent.setAction(action);
	}

	public EventType getSelectedEventType() {
		return model.getEventType(eventTypeList.getSelectedRow());
	}
}
